package io.coderyeah.ymcc.web.controller;

import io.coderyeah.ymcc.domain.CourseDoc;
import io.coderyeah.ymcc.dto.SearchParamDto;
import io.coderyeah.ymcc.result.JSONResult;
import io.coderyeah.ymcc.result.PageList;
import io.coderyeah.ymcc.service.ISearchService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author lqs
 * @date 2022/10/28 10:18
 */
@RestController
@RequestMapping("/search")
public class SearchController {

    @Autowired
    private ISearchService searchService;

    /**
     * 保存索引信息
     *
     * @return jsonResult
     */
    @PostMapping("/save")
    public JSONResult save(@RequestBody CourseDoc doc) {
        searchService.save(doc);
        return JSONResult.success();
    }

    @DeleteMapping("/delete/{id}")
    public JSONResult deleteById(@PathVariable Long id) {
        searchService.deleteById(id);
        return JSONResult.success();
    }


    @PostMapping("/course")
    public JSONResult courseSearch(@RequestBody SearchParamDto dto){
        PageList<CourseDoc> pageList = searchService.searchCourse(dto);
        return JSONResult.success(pageList);
    }
}
